package com.candy.testOfIO;

import java.io.*;

/**
 * @author donglin
 * @Title:
 * @类名: Test01
 * @date 2020/5/28
 */
public class Test01 {
    public static void main(String[] args) {
    test03();
    }

    public static void test03() {
        try(
                BufferedReader is=new BufferedReader(
                        new InputStreamReader(
                                new FileInputStream("F:\\testIo\\SayHi.txt")));

                BufferedWriter os=new BufferedWriter(
                        new OutputStreamWriter(
                                new FileOutputStream("F:\\testIo\\SayHi04.txt")));
        ) {
           String str= is.readLine();

            while (str!=null){
                os.write(str);
//                os.write("\n");
                os.newLine();
                str= is.readLine();


            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


    public static void test02() {
        try(
                Reader is=new FileReader("F:\\testIo\\SayHi.txt");
                Writer os=new FileWriter("F:\\testIo\\SayHi03.txt",true);
        ) {
          char[] b=new char[1024];
            int len=is.read(b);
            while (len!=-1){
                os.write(b,0,len);
                len=is.read();

            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }



    public static void test01() {
        try( InputStream is=new FileInputStream("F:\\testIo\\SayHi.txt");
             OutputStream os=new FileOutputStream("F:\\testIo\\SayHi02.txt",true);
        ) {
             byte[] b=new byte[1024];
            int len=is.read(b);
            while (len!=-1){
                os.write(b,0,len);
                len=is.read();

            }
            //is.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
